CC=gcc
CXX=g++
CFLAGS=-Wall $(DEBUG) $(DEFINITIONS) $(CINCLUDES) $(CMISCFLAGS)
CPPFLAGS=-Wall $(DEBUG) $(EXCEPTIONS) $(CPPINCLUDES) $(DEFINITIONS) $(CPPMISCFLAGS)
DEBUG=-O3 -g3
CMISCFLAGS=
CPPMISCFLAGS=-DGIMI_CLIENT_API=10303
DEFINITIONS=-DLINUX_OS -DGIMI_NO_DATATYPE_INCLUDES
EXCEPTIONS=-fexceptions -ffast-math 
CINCLUDES=-I. -I../../scanmatch -I../../mcl -I$(GDIR)utils
CPPINCLUDES=-I. -I../../scanmatch -I../../mcl $(OCCU_INCLUDE) -I$(GDIR)glutImageGUI -I$(GDIR)utils \
						-I$(GIMDIR)/ImageUtils/JPEGEncoder -I$(GIMDIR)/glutgui $(LNM_UTIL_INCLUDE)

LD=g++
LDFLAGS=
LIBS=-lrt -lssl -lpthread -lGL -lGLU -lglut -ljpeg -lxml2

GDIR=../../../../
GIMDIR=../../../..
LNMDIR=../..
SRCSC=
#SRCSCPP=j2b2.cpp $(OCCU_SRC_CPP)
VPATH=
CPPGIMI=
CGIMI=

CSRCUTIL = $(GIMDIR)/utils/ownutils.c $(GIMDIR)/utils/owndebug.c
CPPIMAGEGUI = $(GIMDIR)/glutImageGUI/glutImageGUI.cpp  $(GIMDIR)/ImageUtils/JPEGEncoder/JPEGEncoder.cpp \
	$(GIMDIR)/glutgui/RGBImage.cpp

CPP_SRC=$(CPPSM) $(CPPMCL) $(CPPIMAGEGUI) $(OCCU_SRC_CPP)
C_SRC=$(CSRCUTIL) 

SRC_PLOT_SCANS=plot_scans.cpp $(CPP_SRC)
CSRC_PLOT_SCANS=$(CSRCUTIL)

SRC_PLOT_SCAN_MEAS=plot_scan_measurement.cpp $(CPPSM) $(CPPMCL) $(CPPIMAGEGUI) $(OCCU_SRC_CPP)
CSRC_PLOT_SCAN_MEAS=$(CSRCUTIL)


#SRC_OCCU_J2B2_TEST=occu_j2b2_test.cpp $(CPPSM) $(CPPMCL) $(CPPIMAGEGUI) $(OCCU_SRC_CPP)
#CSRC_OCCU_J2B2_TEST=$(CSRCUTIL)

## Build GIMI and it's dependencies.
## Files are set to CGIMI and CPPGIMI variables
include Makefile.mcl
include $(LNMDIR)/map/Makefile.occu
include $(LNMDIR)/utils/Makefile.util

CGIMI += $(CMCL)
CPPGIMI += $(CPPMCL) $(CPPSM)

## Construct final lists of CPP and C objects
CPP_OBS=$(CPP_SRC:.cpp=.opp)
C_OBS=$(C_SRC:.c=.o) 

CPPOBJ_PLOT_SCANS=$(SRC_PLOT_SCANS:.cpp=.opp)
COBJ_PLOT_SCANS=$(CSRC_PLOT_SCANS:.c=.o)

CPPOBJ_PLOT_SCAN_MEAS=$(SRC_PLOT_SCAN_MEAS:.cpp=.opp)
COBJ_PLOT_SCAN_MEAS=$(CSRC_PLOT_SCAN_MEAS:.c=.o)

IMAGEGUI_OBS=$(CPPIMAGEGUI:.cpp=.opp)

## Define compiles and links
COMPILEC=$(CC) $(CFLAGS) $(CINCLUDES) -c
COMPILECPP=$(CXX) $(CPPFLAGS) $(CPPINCLUDES) -c
LINK=$(LD) $(LDFLAGS) $(LIBS)

.PHONY: all clean

all: plot_scans plot_scan_measurement plot_occu_map plot_line_map plot3DmapAndPath animate3DTUASwalk plot3DPoints \
	avant600_plotter plot_and_generate_occu_map_targets plot3DRGBPoints


plot_scans: $(COBJ_PLOT_SCANS) $(CPPOBJ_PLOT_SCANS)
						$(LINK) -o $@ $(COBJ_PLOT_SCANS) $(CPPOBJ_PLOT_SCANS)

plot_scan_measurement: $(COBJ_PLOT_SCAN_MEAS) $(CPPOBJ_PLOT_SCAN_MEAS)
						$(LINK) -o $@ $(COBJ_PLOT_SCAN_MEAS) $(CPPOBJ_PLOT_SCAN_MEAS)

plot_occu_map: $(C_OBS) $(CPP_OBS) plot_occu_map.opp
						$(LINK) -o $@ $(C_OBS) $(CPP_OBS) plot_occu_map.opp

plot_and_generate_occu_map_targets: $(C_OBS) $(CPP_OBS) plot_and_generate_occu_map_targets.opp
						$(LINK) -o $@ $(C_OBS) $(CPP_OBS) plot_and_generate_occu_map_targets.opp

avant600_plotter: $(UTIL_ALL_OBS_C) $(IMAGEGUI_OBS) $(UTIL_ALL_OBS_CPP) avant600_plotter.opp
	$(LINK) -o $@ $(UTIL_ALL_OBS_C) $(IMAGEGUI_OBS) $(UTIL_ALL_OBS_CPP) avant600_plotter.opp


plot_line_map: $(C_OBS) $(CPP_OBS) plot_line_map.opp
						$(LINK) -o $@ $(C_OBS) $(CPP_OBS) plot_line_map.opp

plot3DmapAndPath:	$(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp plot3DmapAndPath.opp
						$(LINK) -lSDL -o $@ $(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp plot3DmapAndPath.opp					
						
plot3DPoints:	$(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp plot3DPoints.opp
		$(LINK) -lSDL -o $@ $(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp plot3DPoints.opp
		
plot3DRGBPoints:	$(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp plot3DRGBPoints.opp
		$(LINK) -lSDL -o $@ $(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp plot3DRGBPoints.opp
						

animate3DTUASwalk:	$(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp animate3DTUASwalk.opp
						$(LINK) -lSDL_image -lSDL -o $@ $(C_OBS) $(CPP_OBS) $(GIMDIR)/glutgui/GLUtils.opp animate3DTUASwalk.opp					

clean:
		rm -f $(COBJ_PLOT_SCANS) $(CPPOBJ_PLOT_SCANS) *.opp *.o \
		 plot_scans plot_scan_measurement plot_occu_map\
		*.out *~ *.d *.dpp

## Compile rule for all .o (.c) file
%.o:    %.c
				$(COMPILEC) -o $@ $<

## Compile rule for all .opp (.cpp) files
%.opp:	%.cpp
				$(COMPILECPP) -o $@ $<

## Dependency generation rule: For all required '.d' files
#%.d:	  %.c
#				$(CC) -MM $(CFLAGS) $< > $@.$$$$; \
#				sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
#				rm -f $@.$$$$
#
## Dependency generation rule: For all required '.dpp' files
#%.dpp:	%.cpp
#				$(CXX) -MM $(CPPFLAGS) $< > $@.$$$$; \
#				sed 's,\($*\)\.o[ :]*,\1.opp $@ : ,g' < $@.$$$$ > $@; \
#				rm -f $@.$$$$
#
#%.h:	%.h
#
# Include dependency rules
#-include $(SRCSCPP:.cpp=.dpp) $(CPPGIMI:.cpp=.dpp)
#-include $(SRCSC:.c=.d) $(CGIMI:.c=.d)
